package team.knowers.qzhserver.user.user.entity.dto;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import team.knowers.qzhserver.user.user.entity.dao.UserDO;


import java.util.Collection;

/**
 * @author xtg
 * @date 2024/2/10 15:24
 */
public class UserUserDetails implements UserDetails {
    private UserDO userDO;
//    private List<PermissionDO> permissionDOList;

//    public UserUserDetails(UserDO userDO, List<PermissionDO> permissionDOList) {
//        this.userDO = userDO;
//        this.permissionDOList = permissionDOList;
//    }
    public UserUserDetails(UserDO userDO) {
        this.userDO = userDO;
//        this.permissionDOList = permissionDOList;
    }


    /**
     * @return 当前用户的权限
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        return permissionDOList.stream()
//                .filter(permissionDO -> permissionDO.getValue() != null)
//                .map(permissionDO -> new SimpleGrantedAuthority(permissionDO.getValue()))
//                .collect(Collectors.toList());
        return null;
    }

    @Override
    public String getPassword() {
        return userDO.getPassword();
    }

    @Override
    public String getUsername() {
        return userDO.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return userDO.getRole().equals(1);
    }
}
